package cn.xiyun.xiyuncc.service.impl;

import cn.xiyun.xiyuncc.domain.PayOrder;
import cn.xiyun.xiyuncc.dto.Order2PayDto;
import cn.xiyun.xiyuncc.mapper.PayOrderMapper;
import cn.xiyun.xiyuncc.service.IPayOrderService;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xiyun.maple
 * @since 2023-03-20
 */
@Service
public class PayOrderServiceImpl extends ServiceImpl<PayOrderMapper, PayOrder> implements IPayOrderService {
    /** 根据orderNo查询支付单*/
    @Override
    public PayOrder selectOrderNo(String orderNo) {
      Wrapper<PayOrder> wrapper = new EntityWrapper<>();
      wrapper.eq("order_no",orderNo);
        PayOrder payOrder = super.selectOne(wrapper);
        return payOrder;
    }

    @Override
    public void orderTOPay(Order2PayDto order2PayDto) {
        PayOrder payOrder = new PayOrder();
        payOrder.setAmount(order2PayDto.getAmount());
        payOrder.setUserId(order2PayDto.getLoginId());
        payOrder.setOrderNo(order2PayDto.getOrderNo());
        payOrder.setSubject(order2PayDto.getSubject());
        payOrder.setPayType(order2PayDto.getPayType());
        payOrder.setCreateTime(new Date());
        payOrder.setPayStatus(PayOrder.PAY_WAITING);
        super.insert(payOrder);
    }
}
